package com.hmall.config;



import com.hmall.constant.MqConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class MqConfig {
    @Bean
    public TopicExchange topicExchange(){
        return ExchangeBuilder.topicExchange(MqConstant.ITEM_EXCHANGE).build();
    }
    @Bean
    public Queue insertAndUpdateQueue(){
        return QueueBuilder.durable(MqConstant.ON_SALE).build();
    }
    @Bean
    public Queue deleteQueue(){
        return QueueBuilder.durable(MqConstant.OUT_SALE).build();
    }
    @Bean
    public Binding insertQueueBinding(){
        Binding insertBinding = BindingBuilder
                .bind(insertAndUpdateQueue())
                .to(topicExchange())
                .with(MqConstant.ITEM_ON_SALE_KEY);
        return insertBinding;
    }
    @Bean
    public Binding deleteQueueBinding(){
        Binding deleteBinding = BindingBuilder
                .bind(deleteQueue())
                .to(topicExchange())
                .with(MqConstant.ITEM_OUT_SALE_KEY);
        return deleteBinding;
    }
}
